package com.hope.hotel.controller;

import com.hope.hotel.common.Result;
import com.hope.hotel.entity.dto.AmenitiesDTO;
import com.hope.hotel.entity.dto.LocationDTO;
import com.hope.hotel.entity.dto.PolicyDTO;
import com.hope.hotel.service.HotelService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @作者 TD
 * @日期 2025/5/18
 */
@RestController
@RequestMapping("/hotel")
@RequiredArgsConstructor
public class HotelController {

    private final HotelService hotelService;

    @RequestMapping("/hello")
    public String hello(){
        return "hello";
    }

    @GetMapping("/getHotelsList")
    public Result getHotelsList(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize){
        return hotelService.getHotelList(page, pageSize);
    }
    
    /**
     * 搜索酒店
     * @param destination 目的地(城市或酒店名称)
     * @param checkIn 入住日期
     * @param checkOut 离店日期
     * @param guests 入住人数
     * @param page 页码
     * @param pageSize 每页大小
     * @return 搜索结果
     */
    @GetMapping("/search")
    public Result searchHotels(
            @RequestParam(value = "destination", required = false) String destination,
            @RequestParam(value = "checkIn", required = false) String checkIn,
            @RequestParam(value = "checkOut", required = false) String checkOut,
            @RequestParam(value = "guests", required = false, defaultValue = "1") Integer guests,
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "pageSize", defaultValue = "8") int pageSize) {
        return hotelService.searchHotels(destination, checkIn, checkOut, guests, page, pageSize);
    }
    
    /**
     * 管理员获取酒店位置信息
     */
    @GetMapping("/{hotelId}/location")
    public Result getHotelLocation(@PathVariable String hotelId) {
        return hotelService.getHotelLocation(hotelId);
    }
    
    /**
     * 创建酒店位置信息
     */
    @PostMapping("/{hotelId}/location")
    public Result createHotelLocation(@PathVariable String hotelId, @RequestBody LocationDTO locationDTO, HttpServletRequest request) {
        String adminId = (String) request.getAttribute("adminId");
        locationDTO.setHotelId(hotelId);
        return hotelService.createHotelLocation(locationDTO, adminId);
    }
    
    /**
     * 更新酒店位置信息
     */
    @PutMapping("/{hotelId}/location")
    public Result updateHotelLocation(@PathVariable String hotelId, @RequestBody LocationDTO locationDTO, HttpServletRequest request) {
        String adminId = (String) request.getAttribute("adminId");
        locationDTO.setHotelId(hotelId);
        return hotelService.updateHotelLocation(locationDTO, adminId);
    }
    
    /**
     * 获取酒店政策信息
     */
    @GetMapping("/{hotelId}/policy")
    public Result getHotelPolicy(@PathVariable String hotelId) {
        return hotelService.getHotelPolicy(hotelId);
    }
    
    /**
     * 创建酒店政策信息
     */
    @PostMapping("/{hotelId}/policy")
    public Result createHotelPolicy(@PathVariable String hotelId, @RequestBody PolicyDTO policyDTO, HttpServletRequest request) {
        String adminId = (String) request.getAttribute("adminId");
        policyDTO.setHotelId(hotelId);
        return hotelService.createHotelPolicy(policyDTO, adminId);
    }
    
    /**
     * 更新酒店政策信息
     */
    @PutMapping("/{hotelId}/policy")
    public Result updateHotelPolicy(@PathVariable String hotelId, @RequestBody PolicyDTO policyDTO, HttpServletRequest request) {
        String adminId = (String) request.getAttribute("adminId");
        policyDTO.setHotelId(hotelId);
        return hotelService.updateHotelPolicy(policyDTO, adminId);
    }
    
    /**
     * 获取酒店设施信息
     */
    @GetMapping("/{hotelId}/amenities")
    public Result getHotelAmenities(@PathVariable String hotelId) {
        return hotelService.getHotelAmenities(hotelId);
    }
    
    /**
     * 创建酒店设施信息
     */
    @PostMapping("/{hotelId}/amenities")
    public Result createHotelAmenities(@PathVariable String hotelId, @RequestBody AmenitiesDTO amenitiesDTO, HttpServletRequest request) {
        String adminId = (String) request.getAttribute("adminId");
        amenitiesDTO.setHotelId(hotelId);
        return hotelService.createHotelAmenities(amenitiesDTO, adminId);
    }
    
    /**
     * 更新酒店设施信息
     */
    @PutMapping("/{hotelId}/amenities")
    public Result updateHotelAmenities(@PathVariable String hotelId, @RequestBody AmenitiesDTO amenitiesDTO, HttpServletRequest request) {
        String adminId = (String) request.getAttribute("adminId");
        amenitiesDTO.setHotelId(hotelId);
        return hotelService.updateHotelAmenities(amenitiesDTO, adminId);
    }

    /**
     * 获取酒店详情信息
     * 包括基本信息、房间信息、设施信息等
     */
    @GetMapping("/detail/{hotelId}")
    public Result getHotelDetail(@PathVariable String hotelId) {
        return hotelService.getHotelDetail(hotelId);
    }


}
